package com.towker.frame.test;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

public class ZfmiContextListener extends HttpServlet implements ServletContextListener
{
	Logger log = Logger.getLogger(this.getClass());
	Timer timer = new Timer();
	Date operTime;

	@Override
	public void contextDestroyed(ServletContextEvent arg0)
	{
		// TODO Auto-generated method stub
		log.info("\n 执行应用监听器结束方法       destory context....");
		timer.cancel();
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0)
	{
		// TODO Auto-generated method stub
		log.info("\n 执行应用监听器初始方法      initialcontext....");
		Calendar now = Calendar.getInstance();
		now.add(Calendar.DATE, 1);
		now.set(Calendar.HOUR_OF_DAY, 0);
		now.set(Calendar.MINUTE, 0);
		now.set(Calendar.SECOND, 0);
		now.set(Calendar.MILLISECOND, 0);
		log.info("\n时间now为：   " + now.toString() + "     毫秒数：" + now.getTimeInMillis());
		operTime = new Date(now.getTimeInMillis());
		log.info("\n预设初始执行时间为：   " + operTime);
//		timer.schedule(new FinDataTimerTask(), operTime, 86400000); // 一天执行一次
		timer.schedule(new FinDataTimerTask(),operTime, 10000); //10秒钟执行一次,调试可用
	}
}
